package com.yunfei.blog_mybatis.web.dao;

import com.yunfei.blog_mybatis.web.dataobject.ZhangyunfeiBlog;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface ZhangyunfeiBlogMapper {
    @Delete({
        "delete from zhangyunfei_blog",
        "where article_id = #{articleId,jdbcType=BIGINT}",
          "and author = #{author,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(@Param("articleId") Long articleId, @Param("author") String author);

    @Insert({
        "insert into zhangyunfei_blog (article_id, author, ",
        "gmt_created, title, ",
        "word_count, view_num, ",
        "collection_num, like_num, ",
        "text)",
        "values (#{articleId,jdbcType=BIGINT}, #{author,jdbcType=VARCHAR}, ",
        "#{gmtCreated,jdbcType=TIMESTAMP}, #{title,jdbcType=VARCHAR}, ",
        "#{wordCount,jdbcType=BIGINT}, #{viewNum,jdbcType=BIGINT}, ",
        "#{collectionNum,jdbcType=BIGINT}, #{likeNum,jdbcType=BIGINT}, ",
        "#{text,jdbcType=LONGVARCHAR})"
    })
    int insert(ZhangyunfeiBlog record);

    @Select({
        "select",
        "article_id, author, gmt_created, title, word_count, view_num, collection_num, ",
        "like_num, text",
        "from zhangyunfei_blog",
        "where article_id = #{articleId,jdbcType=BIGINT}",
          "and author = #{author,jdbcType=VARCHAR}"
    })
    @Results(id = "recordMap" ,value = {
        @Result(column="article_id", property="articleId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="author", property="author", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="gmt_created", property="gmtCreated", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="word_count", property="wordCount", jdbcType=JdbcType.BIGINT),
        @Result(column="view_num", property="viewNum", jdbcType=JdbcType.BIGINT),
        @Result(column="collection_num", property="collectionNum", jdbcType=JdbcType.BIGINT),
        @Result(column="like_num", property="likeNum", jdbcType=JdbcType.BIGINT),
        @Result(column="text", property="text", jdbcType=JdbcType.LONGVARCHAR)
    })
    ZhangyunfeiBlog selectByPrimaryKey(@Param("articleId") Long articleId, @Param("author") String author);

    @Select({
            "select",
            "article_id, author, gmt_created, title, word_count, view_num, collection_num, ",
            "like_num, text",
            "from zhangyunfei_blog",
            "where author = #{author,jdbcType=VARCHAR}" ,
            "order by desc",
            " limit 1,8"
    })
    @ResultMap("recordMap")
    List<ZhangyunfeiBlog> selectMyBlog(@Param("author") String author);


    @Select({
        "select",
        "article_id, author, gmt_created, title, word_count, view_num, collection_num, ",
        "like_num, text",
        "from zhangyunfei_blog"
    })
    @Results({
        @Result(column="article_id", property="articleId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="author", property="author", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="gmt_created", property="gmtCreated", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="word_count", property="wordCount", jdbcType=JdbcType.BIGINT),
        @Result(column="view_num", property="viewNum", jdbcType=JdbcType.BIGINT),
        @Result(column="collection_num", property="collectionNum", jdbcType=JdbcType.BIGINT),
        @Result(column="like_num", property="likeNum", jdbcType=JdbcType.BIGINT),
        @Result(column="text", property="text", jdbcType=JdbcType.LONGVARCHAR)
    })
    List<ZhangyunfeiBlog> selectAll();
    @Select({
            "select",
            "article_id, author, gmt_created, title, word_count, view_num, collection_num, ",
            "like_num, text",
            "from zhangyunfei_blog",
            "limit 1,8"
    })
    @ResultMap("recordMap")
    List<ZhangyunfeiBlog> selectbypage();
    @Update({
        "update zhangyunfei_blog",
        "set gmt_created = #{gmtCreated,jdbcType=TIMESTAMP},",
          "title = #{title,jdbcType=VARCHAR},",
          "word_count = #{wordCount,jdbcType=BIGINT},",
          "view_num = #{viewNum,jdbcType=BIGINT},",
          "collection_num = #{collectionNum,jdbcType=BIGINT},",
          "like_num = #{likeNum,jdbcType=BIGINT},",
          "text = #{text,jdbcType=LONGVARCHAR}",
        "where article_id = #{articleId,jdbcType=BIGINT}",
          "and author = #{author,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(ZhangyunfeiBlog record);
}